package com.example.lee1.controller;

import com.example.lee1.entity.TestTableEntity;
import com.example.lee1.service.TestTableService;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-13 16:12:03
 */
@RestController
@RequestMapping("generator/testtable")
public class TestTableController {
  @Autowired private TestTableService testTableService;

  @Autowired RedisTemplate redisTemplate;

  /** 列表 */
  @RequestMapping("/list")
  @RequiresPermissions("generator:testtable:list")
  public R list(@RequestParam Map<String, Object> params) {
    long start = System.currentTimeMillis();
    //    PageUtils page = testTableService.queryPage(params);
    List<TestTableEntity> page = testTableService.queryPage(params);
    long end = System.currentTimeMillis();
    System.out.println("程序运行时间： " + (end - start) + "ms");
    return R.ok().put("data", page);
  }

  /** 信息 */
  @RequestMapping("/info/{id}")
  @RequiresPermissions("generator:testtable:info")
  public R info(@PathVariable("id") Long id) {
    TestTableEntity testTable = testTableService.getById(id);

    return R.ok().put("testTable", testTable);
  }

  /** 保存 */
  @RequestMapping("/save")
  @RequiresPermissions("generator:testtable:save")
  public R save(@RequestBody TestTableEntity testTable) {
    testTableService.save(testTable);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  @RequiresPermissions("generator:testtable:update")
  public R update(@RequestBody TestTableEntity testTable) {
    testTableService.updateById(testTable);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  @RequiresPermissions("generator:testtable:delete")
  public R delete(@RequestBody Long[] ids) {
    testTableService.removeByIds(Arrays.asList(ids));

    return R.ok();
  }
}
